const fs = require('fs')
const chalk = require('chalk')
const { editFile } = require('../utils')
    /**
     * @function 模板一定制化
     * @param {*} answer 用户配置内容
     * @param {*} path 用户生成的路径
     */
async function editT1PageConfig(answer, path) {
    const { pageName, namespace, listenRouter } = answer
    let content = `export default {
        pageName: '${pageName}',
        namespace: '${namespace}',
        listenRouter: '${listenRouter}',
    }`
    let pageConfigPath = path + '/config/pageConfig.ts'
    await editFile(pageConfigPath, content, (text) => {
        console.log(chalk.red(text))
        process.exit(0)
    })
}
/**
 * @function 新增,编辑,详情模板
 * @param {*} answer 用户配置内容
 * @param {*} path 用户生成的路径
 */
async function editT4PageConfig(answer, path) {
    const { listenAddRouter, namespace, listenEditRouter, listenDetailRouter } = answer
    let content = `export default {
        namespace: '${namespace}',
        listenAddRouter: '${listenAddRouter}',
        listenEditRouter: '${listenEditRouter}',
        listenDetailRouter: '${listenDetailRouter}',
    }`
    let pageConfigPath = path + '/config/pageConfig.ts'
    await editFile(pageConfigPath, content, (text) => {
        console.log(chalk.red(text))
        process.exit(0)
    })
}
/**
 * @function 新增,编辑,详情表单模板
 * @param {*} answer 用户配置内容
 * @param {*} path 用户生成的路径
 */
async function editT6PageConfig(answer, path) {
    const { listenAddRouter, namespace, listenEditRouter, listenDetailRouter, addName, editName, detailName } = answer
    let content = `export default {
        namespace: '${namespace}',
        listenAddRouter: '${listenAddRouter}',
        listenEditRouter: '${listenEditRouter}',
        listenDetailRouter: '${listenDetailRouter}',
        addName: '${addName}',
        editName: '${editName}',
        detailName: '${detailName}',
    }`
    let pageConfigPath = path + '/config/pageConfig.ts'
    await editFile(pageConfigPath, content, (text) => {
        console.log(chalk.red(text))
        process.exit(0)
    })
}
module.exports = {
    editT1PageConfig,
    editT4PageConfig,
    editT6PageConfig
}